﻿<!DOCTYPE html>
<!--承包商名录管理-编辑-->
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="/static/js/common.js"></script>
    <link href="/static/js/vue-treeselect/vue-treeselect.css" rel="stylesheet" />
    <script src="/static/js/vue-treeselect/vue-treeselect.js"></script>

    <style>
        .el-dialog__body {
            height: 100% !important;
        }

        .el-dialog.is-fullscreen {
            overflow: hidden !important;
        }
    </style>
</head>

<body>
    <div id="app" v-cloak class="popupW100">
        <el-form :model="Form" status-icon :rules="rules" ref="ruleForm" label-width="100px" size="mini"
                 label-position="right">

            <el-row>
                <el-col :span="11">
                    <div class="elst-select-mini">
                        <el-form-item prop="cbs_list.contractorName">
                            <el-input type="text" v-model="Form.cbs_list.contractorName" autocomplete="off" size="mini">
                                <template slot="prepend">
                                    {{ContractorDirectory.ContractorName+mark.m}}
                                </template>
                            </el-input>
                            <span class="iputLineMust" v-if="!Form.cbs_list.contractorName">
                                <!-- 必填项添加 -->
                                <img src="/static/images/exclamation.png" alt="">
                            </span>
                        </el-form-item>
                    </div>
                </el-col>
                <el-col :span="11" :offset="2">
                    <div class="elst-select-mini">
                        <el-form-item prop="cbs_list.contractorCode">
                            <el-input type="text" v-model="Form.cbs_list.contractorCode" autocomplete="off" size="mini">
                                <template slot="prepend">
                                    {{ContractorDirectory.ContractorCode+mark.m}}
                                </template>
                            </el-input>
                            <span class="iputLineMust" v-if="!Form.cbs_list.contractorCode">
                                <!-- 必填项添加 -->
                                <img src="/static/images/exclamation.png" alt="">
                            </span>
                        </el-form-item>
                    </div>
                </el-col>
                <el-col :span="11">
                    <div class="elst-select-mini">
                        <el-form-item prop="cbs_list.constructionCategory">
                            <el-input size="mini">
                                <template slot="prepend">
                                    <div> {{ContractorDirectory.ConstructionCategory+mark.m}}</div>
                                </template>
                                <el-select @visible-change="visibleChange" v-model="Form.cbs_list.constructionCategory" slot="suffix"
                                           :placeholder="ContractorDirectory.ConstructionCategory">
                                    <el-option label="请选择" value=""></el-option>
                                    <el-option v-for="item in ConstructionCategory" :label="item.value"
                                               :value="item.key">
                                    </el-option>
                                </el-select>
                            </el-input>
                            <span class="iputLineMust" v-if="!Form.cbs_list.constructionCategory">
                                <!-- 必填项添加 -->
                                <img src="/static/images/exclamation.png" alt="">
                            </span>
                        </el-form-item>
                    </div>
                </el-col>
                <el-col :span="24">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input size="mini">
                                <template>
                                    {{ContractorDirectory.OtherConstructionCategory+mark.m}}
                                </template>
                            </el-input>
                            <el-checkbox-group v-model="checkedlist">
                                <el-checkbox v-for="c in ConstructionCategory" :label="c.key">{{c.value}}</el-checkbox>
                            </el-checkbox-group>
                        </el-form-item>
                    </div>
                </el-col>
                <el-col :span="11">
                    <div class="elst-select-mini vue-treeselect_style">
                        <el-form-item>
                            <el-input size="mini">
                                <template slot="prepend">
                                    {{ContractorDirectory.Administration+mark.m}}
                                </template>
                                <treeselect v-model="departmentID" :options="department" :flat="true" slot="suffix"
                                            style="line-height: 28px;width:70%;float: right;" placeholder="请选择" />
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>
                <el-col :span="11" :offset="2">
                    <div class="elst-select-mini">
                        <el-form-item prop="cbs_list.principalName">
                            <el-input type="text" v-model="Form.cbs_list.principalName" autocomplete="off" size="mini">
                                <template slot="prepend">
                                    {{ContractorDirectory.PrincipalName+mark.m}}
                                </template>
                            </el-input>
                            <span class="iputLineMust" v-if="!Form.cbs_list.principalName">
                                <!-- 必填项添加 -->
                                <img src="/static/images/exclamation.png" alt="">
                            </span>
                        </el-form-item>
                    </div>
                </el-col>
                <el-col :span="11">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input type="text" v-model="Form.cbs_list.idNumber" autocomplete="off" size="mini">
                                <template slot="prepend">
                                    {{ContractorDirectory.IDNumber+mark.m}}
                                </template>
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>
                <el-col :span="11" :offset="2">
                    <div class="elst-select-mini">
                        <el-form-item prop="cbs_list.phone">
                            <el-input type="text" v-model="Form.cbs_list.phone" autocomplete="off" size="mini">
                                <template slot="prepend">
                                    {{ContractorDirectory.contact+mark.m}}
                                </template>
                            </el-input>
                            <span class="iputLineMust" v-if="!Form.cbs_list.phone">
                                <!-- 必填项添加 -->
                                <img src="/static/images/exclamation.png" alt="">
                            </span>
                        </el-form-item>
                    </div>
                </el-col>
                <!--<el-col :span="11" :offset="2">
                    <div class="elst-select-mini">
                        <el-form-item>

                            <el-input type="text" v-model="Form.cbs_list.age" autocomplete="off" size="mini">
                                <template slot="prepend">
                                    {{ContractorDirectory.Age+mark.m}}
                                </template>
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>-->
                <el-col :span="11">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input type="text" v-model="Form.cbs_list.qualificationName" autocomplete="off" size="mini">
                                <template slot="prepend">
                                    {{ContractorDirectory.Qualification+mark.m}}
                                </template>
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>
                <el-col :span="11" :offset="2">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input type="text" v-model="Form.cbs_list.qualificationLevel" autocomplete="off" size="mini">
                                <template slot="prepend">
                                    {{ContractorDirectory.QualificationLevel+mark.m}}
                                </template>
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>
                <el-col :span="24">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <div class="el-input--mini el-input-group">
                                <div class="el-input-group__prepend">
                                    {{ContractorDirectory.TechnicalStaffSituation+mark.m}}
                                </div>
                                <el-input class="el-textarea__inner" type="textarea"
                                          v-model="Form.cbs_list.technicalStaffSituation" autocomplete="off"></el-input>
                            </div>
                        </el-form-item>
                    </div>
                </el-col>
                <el-col :span="24">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <div class="el-input--mini el-input-group">
                                <div class="el-input-group__prepend">
                                    {{ContractorDirectory.MainaAchievement+mark.m}}
                                </div>
                                <el-input class="el-textarea__inner" type="textarea"
                                          v-model="Form.cbs_list.mainaAchievement" autocomplete="off"></el-input>
                            </div>
                        </el-form-item>
                    </div>
                </el-col>
            </el-row>
            <el-row>
                <el-col class="head-tool">
                    <!--<btn-uploadfile-list text="请选择上传附件" url="/api/File/UploadFile" accept=".jpg,.png" @success="successUpLoad"></btn-uploadfile-list>-->
                    <el-upload name="files" class="fl" ref="Attachmentupload" action="/api/File/UploadFile" multiple="true"
                               :before-upload="beforeUpload" :on-success="successUpLoad" :auto-upload="true"
                               :show-file-list="false">
                        <el-button type="primary">{{col.lawUploadAttachment}}</el-button>
                    </el-upload>
                </el-col>
            </el-row>
            <el-row>
                <el-col span="24">
                    <el-table stripe :data="Form.cbs_list.cbS_ListAttachments" style="width: 100%">
                        <el-table-column type="index" :label="col.SequenceNumber" :index="indexMethod" width="50"
                                         show-overflow-tooltip="true"></el-table-column>
                        <el-table-column prop="name" :label="ContractorDirectory.FileName">
                            <template slot-scope="scope">
                                <el-button type="text" @click="label_click(scope.row.path)">
                                    {{scope.row.name}}
                                </el-button>
                            </template>
                        </el-table-column>
                        <el-table-column prop="uploadTime" :label="ContractorDirectory.CreateTime"
                                         show-overflow-tooltip="true">
                        </el-table-column>
                        <el-table-column prop="sysUser.sysUserInfor.name" :label="ContractorDirectory.UploadUser"
                                         show-overflow-tooltip="true">
                        </el-table-column>
                        <el-table-column label="操作">
                            <template slot-scope="scope">
                                <el-button @click.native.prevent="deleteRow(scope.$index, Form.cbs_list.cbS_ListAttachments)"
                                           type="text" size="small">
                                    移除
                                </el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                </el-col>
            </el-row>
            <br>
            <el-row type="flex" justify="end" style="margin-top:10px">
                <el-form-item>
                    <el-button type="primary" @click="onSubmitForm('ruleForm')">{{col.btnSave}}</el-button>
                    <el-button type="primary" @click="onBack">{{col.btnBack}}</el-button>
                </el-form-item>
            </el-row>
        </el-form>
        <br>
        <br>
    </div>
    <script type="text/javascript">
        var uploadText = "请选择上传文件";
        Vue.component('treeselect', VueTreeselect.Treeselect);
        var app = new Vue({
            el: '#app',
            data: {
                id: '',
                Title: '',
                UploadFileApiUrl: API_UPLOADFILE_URL,
                //业务表单内容
                Form: {
                    cbs_list: { createDept: '', constructionCategory: '', cbS_ListAttachments: [], otherConstructionCategory: '' },
                    sysUser: { id: '', name: '' },
                },
                //部门数据集
                department: [],
                departmentID: "",
                checkedlist: [],
                ConstructionCategory: [],
                CheckProjectList: [],
                ListItem: ListItem,
                PrincipalName: [],
                //表单验证
                rules: {
                    'cbs_list.contractorName': [
                        verification.NotNull,
                        { pattern: verification.StringLengthAtoB.t.format(2, 50), message: verification.StringLengthAtoB.m.format(2, 10), trigger: 'blur' }
                    ],
                    'cbs_list.contractorCode': [
                        verification.NotNull
                    ],
                    'cbs_list.constructionCategory': [
                        verification.NotNull
                    ],
                    'cbs_list.principalName': [
                        verification.NotNull
                    ],
                    'cbs_list.phone': [
                        verification.NotNull
                    ]
                }
            },
            watch: {
                //监听设置工厂
                departmentID: function (val) {
                    var mythis = this;
                    myAjax("get", this, '/api/SysDepartment/Get?id=' + val, null, function (response) {
                        mythis.Form.cbs_list.ManageDept = response.data.id;
                        //mythis.Form.cbs_list.createFactory = response.data.createFactory;
                    }, false);
                }
            },
            methods: {
                //解決edge下select bug
                visibleChange: function (isVisible) {
                    visibleChange(isVisible)
                },
                indexMethod: function (index) {
                    return (this.ListItem.currentPage - 1) * this.ListItem.pagesize + index + 1;
                },
                //提交数据
                onSubmitForm: function (formName) {
                    var mythis = this;
                    this.$refs[formName].validate(function (valid) {
                        //验证通过
                        if (valid) {
                            for (var i = 0; i < mythis.Form.cbs_list.cbS_ListAttachments.length; i++) {
                                mythis.Form.cbs_list.cbS_ListAttachments[i].sysUser = null;
                            }
                            console.log('222', mythis.checkedlist);
                            mythis.Form.cbs_list.otherConstructionCategory = mythis.checkedlist.toString();

                            onSubmitForm(this, '/api/CBS_List/Save', mythis.Form.cbs_list);
                        } else {
                            //验证失败
                            return false;
                        }
                    });
                },
                getData: function () {
                    getData(this, '/api/CBS_List/get?id=' + this.id);
                    if (this.Form.cbs_list.otherConstructionCategory) this.checkedlist = this.Form.cbs_list.otherConstructionCategory.split(",");
                    console.log('333', this.checkedlist);
                },
                onBack: function () {
                    parent.app.ListItem.dialogVisible = false;
                },
                label_click: function (path) {
                    location.href = path;
                },
                //移除附件
                deleteRow: function (index, rows) {
                    rows.splice(index, 1);
                },
                //上传附件文件的校验
                beforeUpload: function (file) {
                    const isJPG = file.type === 'image/jpeg';
                    const isPNG = file.type === 'image/png';
                    const isLt2M = file.size / 1024 / 1024 < 2;
                    if (!isJPG && !isPNG) {
                        this.$message.error('仅可上传 JPG和PNG 格式!');
                    }
                    if (!isLt2M) {
                        this.$message.error('上传图片大小不能超过 2MB!');
                    }
                    return (isJPG || isPNG) && isLt2M;
                },
                //上传成功后执行
                successUpLoad: function (res, file) {
                    var data = res.data;//成功后的业务数据
                    var fileModel = data[0];//第一个文件对象
                    var d = new Date();
                    this.Form.cbs_list.cbS_ListAttachments.push({
                        attachment: fileModel.id,
                        path: downLoadPath(fileModel.id),
                        name: file.name,
                        cbS_ListId: this.id,
                        uploadTime: new Date(d.setHours(d.getHours() + 8)).toJSON().substr(0, 19).replace('T', ' '),
                        uploadUser: this.Form.sysUser.id,
                        sysUser: {
                            sysUserInfor: { name: this.Form.sysUser.name, }
                        }
                    });
                },
                //初始化部门下拉树(完成)
                getDepartmentData: function () {
                    var mythis = this;
                    myAjax("post", this, '/api/SysDepartment/GetList', { model: { Name: '', Code: '', CreateFactory: this.createfactoryID }, offset: 0, limit: 100 }, function (response) {
                        mythis.department = menuHelper(response.data.pageData, guidEmpty)
                        console.log('h1', response.data.pageData);
                        console.log('h2', mythis.department);
                    }, false);
                }
            },
            mounted: function () {
                this.ConstructionCategory = getDicData('cbssglb');
                console.log('ConstructionCategory', this.ConstructionCategory);
                this.id = getUrlParam("id");
                //this.departmentID = getUrlParam("DId");
                this.createfactoryID = getUrlParam("FId");
                //初始化部门下拉树数据
                this.getDepartmentData();
                this.getData();
                console.log('111', this.checkedlist);
                this.departmentID = this.Form.cbs_list.manageDept;
            }
        });
        //下拉树数据格式化
        function menuHelper(list, pid) {
            var result = [];
            if (list.length <= 0)
                return list;
            list.forEach(function (v, i) {
                var temp = {};
                for (var key in v) {
                    temp[key] = v[key];
                }
                temp.label = v.name;
                temp.parentId = temp.parentId ? temp.parentId : guidEmpty;
                var obj;
                if (temp.parentId == pid) {
                    obj = temp;
                    var nextObj = menuHelper(list, temp.id);
                    if (nextObj.length > 0) {
                        obj.children = nextObj;
                    }
                }
                if (obj)
                    result.push(obj)
            })
            return result;

        }
    </script>
</body>

</html>